package com.gang.mars.basic.enumdeom;

import java.util.EnumSet;
import java.util.Set;

/**
 * @author gang.chen
 * @description
 * @Date 2021/7/2 8:24
 */
public class C {

    public static void main(String[] args) {
        GangAdapt[] values = GangAdapt.values(true, true);
        System.out.println(values.length);
    }

    enum GangAdapt
    {
        CLASS_TO_STRING,
        ANNOTATION_TO_MAP;

        protected final boolean isIn(GangAdapt... adaptations)
        {
            for (GangAdapt adaptation : adaptations)
            {
                if (adaptation == this) {
                    return true;
                }
            }
            return false;
        }

        public static GangAdapt[] values(boolean classToString, boolean annotationsToMap)
        {
            EnumSet<GangAdapt> result = EnumSet.noneOf(GangAdapt.class);
            addIfTrue(result, GangAdapt.CLASS_TO_STRING, classToString);
            addIfTrue(result, GangAdapt.ANNOTATION_TO_MAP, annotationsToMap);
            return result.toArray(new GangAdapt[0]);
        }

        private static <T> void addIfTrue(Set<T> result, T value, boolean test)
        {
            if (test) {
                result.add(value);
            }
        }
    }
}
